﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if NETFX_CORE
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

#else
using System.Windows;
using System.Windows.Controls;

#endif

namespace StyleMVVM.View.Impl
{
	internal class TextChangedBindingHelper
	{
		public static string GetValue(DependencyObject obj)
		{
			return (string)obj.GetValue(ValueProperty);
		}

		public static void SetValue(DependencyObject obj, string value)
		{
			obj.SetValue(ValueProperty, value);
		}

		// Using a DependencyProperty as the backing store for Value.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty ValueProperty =
			DependencyProperty.RegisterAttached("Value",
			                                    typeof(string),
			                                    typeof(TextChangedBindingHelper),
			                                    new PropertyMetadata(null, ValueChangedHandler));

		private static void ValueChangedHandler(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			TextBox textBox = (TextBox)d;

			textBox.Text = (string)e.NewValue;
		}
	}
}